;; Start by calling the make-slippery-chicken function. 
(make-slippery-chicken  

 ;; Define a variable for the music created, so that it can be passed to the 
 ;; routines for creating outupt. 
 '+primary-disposition+ 

 ;; The following is then the title used for the LilyPond files themselves (not 
 ;; the title of the piece within the sheet music). It should therefore have 
 ;; no spaces in it. 
 :title "Primary-Disposition" 

 ;; Now define the ensemble. The :instrument-palette keyword here points to the 
 ;; list of instruments (and their ranges etc.) currently assigned to the
 ;; global parameter +slippery-chicken-standard-instrument-palette+. That
 ;; parameter is defined in the file instruments.lsp. A description of how to
 ;; extend or modify this list, or create your own, will be found in a later
 ;; help file.   
 :instrument-palette +slippery-chicken-standard-instrument-palette+ 

 ;; In this block you assign variables to each one of the instruments from the 
 ;; :instrument-palette that you intend to use and indicate which MIDI channels 
 ;; those instruments are to be played back on.  

 ;; The first variable is chosen by the user for the scope of this script; the 
 ;; second is the name of the instrument as defined in instruments.lsp. 
 ;; NB: If you think you might use LilyPond for the typeset output at some 
 ;; point, you cannot use numbers in your variable names (eg. violin1), as 
 ;; LilyPond's parser does not accept them. (Use instead violinOne, for
 ;; example).  
 :ensemble '(((flt (flute :midi-channel 1))
	      (tpt-c (c-trumpet :midi-channel 2))
	      (vln-one (violin :midi-channel 3)) 
              (vln-two (violin :midi-channel 4)) 
              (vla (viola :midi-channel 5)) 
              (cel (cello :midi-channel 6))
	      (db (double-bass :midi-channel 7))))

 ;; Now set the tempo for each section. The first number of this list is the ID 
 ;; of the section of the piece for which the following tempo is valid. If only 
 ;; one section is given, the tempo applies to the entire piece. These section 
 ;; IDs correspond to the section IDs listed in all of the -maps (i.e. the 
 ;; :set-map and :rthm-seq-map below.) 

 ;; Rythmic values here and below can use the Score/CMN alphabetic 
 ;; representations. These are s=sixteenth, e=eigth, q=quarter, h=half and 
 ;; w=whole, with a period after these (e.g. q.) representing a dotted 
 ;; value. The tempo-map stated here thus means that starting in section 1, the  
 ;; tempo will be quarter = 84.  
 :tempo-map '((1 (q 84)))

 ;; This line is for CMN output and refers to the page layout, whereby in this 
 ;; example there will be three measures per system.  
 :bars-per-system-map '((1 3))

 ;; This is where the harmonic material is entered. Each of the following lists 
 ;; represent a vertical sonority (pitch set). The first element of each 
 ;; list is the sonority's ID, and will be used in the set-map, below, to 
 ;; produce the piece's harmonic progression.  

 ;; The sets defined here can be used in any order in the set-map. They apply 
 ;; to the entire ensemble for any given moment within the composition. They 
 ;; consist of note names with octave designations, whereby middle-C is C4, the 
 ;; C above is C5, and the B-natural below middle-C is B3. Flats are indicated 
 ;; using "f", thus the B-flat below middle-C is bf3. Sharps are indicated 
 ;; using "s" in the same manner. Microtonal options are also available and 
 ;; will be covered elsewhere. More advanced usages of slippery chicken allow 
 ;; for the creation of harmonic subsets, as will also be covered elsewhere.   
 :set-palette '((set1 ((c4 d4 f4 g4 a4 c5))) 
		(set2 ((f3 g3 a3 c4 d4 f4 g4 a4 c5 d5 f5)))
		(set3 ((c3 d3 f3 g3 a3 c4 d4 f4 g4 a4 c5 d5 f5 g5 a5 c6))) 
		(set4 ((c2 d2 f2 g2 a2 c3 d3 f3 g3 a3 c4 d4 f4 g4 a4 c5 d5 f5
			   g5 a5 c6 d6 f6 g6 a6 c7)))) 

 ;; The :set-map keyword is where the harmonic progression of the piece is 
 ;; defined. The first number of each list is the section ID of the piece, and  
 ;; corresponds to the section ID of the other -maps in this file. The list of 
 ;; numbers following the section ID is a sequence of the IDs of the vertical 
 ;; sonorities (chords) defined in the :set-palette.  
 :set-map '((1 (set1 set1 set1 set1 set1))
	    (2 (set2 set3 set2 set3 set2 set3 set3)) 
	    (3 (set3 set3 set4 set3 set4 set3 set4 set4 set3 set4 set4))  
	    (4 (set4 set4 set1 set4 set1 set4 set1 set1 set1 set4 set1 set1
		set1 set1 set1)))   

 ;; Now you define your rhythmic motifs within the rhythm sequence palette. You 
 ;; can define any number of sequences and use or omit any number of those 
 ;; defined. 

 ;; Each rhythm sequence is given an ID (here simple integers). The sequences 
 ;; can be more than one measure long, in which case each measure is enclosed 
 ;; in parentheses as a list. 

 ;; The syntax of the rhythm sequences is partly borrowed from Score/CMN and 
 ;; partly devised for slippery-chicken. See the parse-rhythms function in the 
 ;; rthm-seq-bar.lsp file for details.  

 ;; The rhythm sequences defined here will then be organized and combined in 
 ;; the rhythm sequence map below. Any two simultaneously occuring rhythm 
 ;; sequences in the :rthm-seq-map must be of the same length, although you can  
 ;; define as many of different lengths as you desire. For now we'll leave all 
 ;; of our rhythm sequences equal in length so that all combinations are 
 ;; possible.   

 ;; As seen above, the first element in the list is the rhtyhm's ID. The first 
 ;; list within the list is the time signature, indicated as the upper number 
 ;; of the time signature followed by the lower, enclosed in parentheses.  

 ;; All rhythmic values can be written in numeric form. A whole note is 1; a 
 ;; half note is 2; a quarter note is 4; an eigth note is 8; a sixteenth note 
 ;; is 16; a thirty-second note is 32 and so forth.  

 ;; A number of the rhythmic values can also be written using an alphabetic 
 ;; shorthand borrowed from Score, Common Music, and Common Music 
 ;; Notation. Here, a whole note can be indicated by w, a half note by h, 
 ;; a quarter note by q, an eighth by e, and a sixteenth by s. Any 
 ;; smaller values must be notated using numerals. 

 ;; Dotted values are indicated by placing a dot preceeded by a backward slash 
 ;; after the numerical value, such as 8\. for a dotted eighth. When using the 
 ;; alphabetic shorthand, the backward slash is omitted (ie, e. for a dotted 
 ;; eighth). 

 ;; Tied notes are indicated by either placing a backward slash and a plus sign 
 ;; immediately between two numerical values (such as 16\+8), with no space 
 ;; between them, or by placing a backward slash and a plus sign immediately 
 ;; before a single numerical value (such as \+8), to indicate that it is to be 
 ;; retroactively tied to the previous value. The latter approach is how to 
 ;; construct ties over bar lines. When using the alphabetic shorthand, the 
 ;; backward slash is omitted (ie, s+e and +e).   

 ;; Rhythmic values in parenetheses represent rests of the given duration. Dots 
 ;; and ties function the same way for rests as for notes.  

 ;; Tuplets (triplets, quintuplets etc.) are indicated using curly brackets 
 ;; {}. The first number after the opening curly bracket is the number of the 
 ;; tuplet; 3 indicates a triplet, 5 a quintuplet, 7 a septuplet and so 
 ;; on. There must be white space before and after each curly bracket of a 
 ;; tuplet, otherwise running the script will abort with an error message. 

 ;; Tuplet rhythmic durations can also be written as numerical values. To 
 ;; determine the numerical value for each beat of a tuplet, you must multiply 
 ;; the number of the tuplet (3 for triplet, 5 for quintuplet etc.) by the 
 ;; duration it is to subdivide. For example, the numerical value for each half 
 ;; note duration in a triplet spanning a whole note (three triplet half notes) 
 ;; would be determined by multiplying 3 x 1. Thus, a triplet of half-notes 
 ;; would be written { 3 3 3 3 }. A triplet of quarter notes would take the 
 ;; rhythmic space of a half note, so each triplet quarter within that triplet 
 ;; would be notated as 3 x 2 = 6, or { 3 6 6 6 } to obtain a figure of three 
 ;; triplet quarters over the space of a half note.   

 ;; A longer duration within a given triplet is achieved by reducing the 
 ;; numerical value. A half note is twice as long as a quarter; thus, in the 
 ;; same way that a quarter = 4 and a half note = 2, then within a triplet 
 ;; figure a quarter = 6 and a half note = 3. A triplet figure consisting of a 
 ;; triplet-half-note and a triplet-quarter in the space of one half note would 
 ;; be written { 3 3 6 }. A quintuplet figure consisting of a quintuplet 16th, 
 ;; a quintuplet 8th, and two quintuplet 16ths in the space of one quarter 
 ;; would be written { 5 20 10 20 20} (5 in the space of a quarter (4) = 20 for 
 ;; each quintuplet quarter).   

 ;; An alphabetic shorthand is available for triplets and quintuplets in 
 ;; combination with the s, e, q, h, and w shorthand. In this case, within the  
 ;; tuplet bracket, a triplet eighth is notated as te, a quintuplet sixteenth 
 ;; as fs (f for "five"-tuplet) etc.   

 ;; By default, slippery chicken produces scores with no beams. To indicate 
 ;; where beams are to be placed within the printed notation use the - 
 ;; indicator. Place a hyphen before each note where the beam is to begin and 
 ;; after each note where the beam is to end. At the moment, beams will be 
 ;; placed over rests within a figure, but not a the start of a figure. There 
 ;; is no option currently for stemlets over rests. 
 :rthm-seq-palette
 '((seq1 ((((4 4) - 16 16 8 - { 5 - 20 10 20 20 - } { 3 3 6 } )   
	   ( - s s s s - - (s) s s s - - +e. s - q))   

	  ;; Now we construct the melodic contour of the figure. It is important
	  ;; to stress that you cannot achieve pitch-accurate output. That is not
	  ;; the focus of slippery-chicken. Instead, the pitch sequence palette
	  ;; will represent the general melodic shape of the pitches which
	  ;; slippery chicken chooses for the given rhythm sequence.

	  ;; The contour will then be applied to the playable range of the given
	  ;; instrument as it sits within the pitch set for that grouping of that
	  ;; section. If the given pitch set only goes as high as e4, for example,
	  ;; any pitch-sequence contour given to the flute for that passage will
	  ;; be scaled to fall between C4 and E4, as the flute's range only begins
	  ;; with middle-C.

	  ;; The numbers of the pitch sequence cannot be lower than 1, but can be
	  ;; arbitrarily high, as the scaling will be applied to the playable
	  ;; register within the instrument's range and the pitch set. The user
	  ;; can indicate that the pitches chosen by slippery-chicken are to fall
	  ;; in the upper half of an instrument's playable register for a given
	  ;; pitch set by, for example, having the uppermost numerical value in
	  ;; the list be 10 and the lowermost be 5, etc. For a full use of the
	  ;; playable register be sure to include a 1 in the pitch sequence
	  ;; (although, if there are only two playable pitches available on an
	  ;; instrument for a given passage that has a pitch contour
	  ;; containing numerals from 1 to 10, any number under 5 will
	  ;; result in the first of those pitches being selected, and
	  ;; any number from 6 to 10 will result in the second pitch
	  ;; being selected).  

	  ;; There can be as many pitch lists as the user desires. They will cycle through
	  ;; the instruments, first through the highest instrument for the
	  ;; duration of that section of that part, then to the next highest
	  ;; instrument using the same rhythm sequence etc.  


	  ;; Numbers in parentheses indicate chords (or double-/triple-stops,
	  ;; multiphonics etc.) For our first example we will just use one pitch
	  ;; sequence for each rhythm sequence, with no chords.
	  :pitch-seq-palette (1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9)

	  ;; Dynamics, articulations, many performance techniques, and slurs are
	  ;; added for both CMN and LilyPond output using the :cmn-marks keyword
	  ;; followed by a list. The list indicates the mark to be added (such as
	  ;; "a" for an accent or "s" for staccato) and the rhythms within
	  ;; the rhythm sequence to which those marks are to be applied. The
	  ;; indication (a 1 s 3), therefore, results in an accent being placed on
	  ;; the first note of the rhythm sequence and a staccato dot being placed
	  ;; on the third. Separate marks are included sequentially in the same
	  ;; list separated only by a space (as seen below). Slurs are indicated
	  ;; by two numerals, the first being the note where the slur begins, and
	  ;; the second the note where it ends. 

	  ;; NB: The marks are added to elements of the rhythm sequence, not the
	  ;; pitch sequence; this can cause confusion when counting notes for
	  ;; placement, as two tied rhythmic values are counted as two notes for
	  ;; this function.  

	  ;; A complete list of the marks available can be found elsewhere on this
	  ;; wiki, as well as in the source code documentation files for cmn.lsp
	  ;; and lilypond.lsp. 
	  :cmn-marks (mp 1 a 1 s 3 slur 1 3 a 4 slur 4 7 s 9 a 10 slur 16
			 18)))  
   (seq2 ((((4 4) - e e - - s s s s - - (s) s (s) s - { 3 - te te te - } ) 
	   ( - s s s (s) - - { 3 te te (te) - } q \+8 (e) )) 
	  :pitch-seq-palette (11 10 9 11 10 8 7 11 10 6 5 11 10 9 8 7 11) 
	  :cmn-marks (mf 1 s 1 2 a 3 slur 3 4 a 5 slur 5 6 s 7 s 8 a 9 slur 9 11 a
			 12 slur 12 14 s 15 16 a 17))) 
   (seq3 ((((4 4) { 3 - te te te - } - e e - - s s s s - - (s) s (s) s - ) 
	   (- s s s s - - s s s s - { 3 - te te te - } { 3 - +te te te - } )) 
	  :pitch-seq-palette (1 2 1 2 3 1 2 3 4 5 6 1 2 3 5 4 4 4 2 7 5 4 5 6) 
	  :cmn-marks (f 1 slur 1 3 a 4 s 4 5 slur 6 7 slur 8 9 s 10 11 slur 12 13
			slur 14 15 a 16 slur 18 19 slur 20 21 a 22 slur 24 25))) 
   (seq4 ((((4 4) - s s (s) s - - s s (e) - - e s (s) - { 3 - te te te - } ) 
	   ( { 5 - 10 10 20 - } - +s s s s - - (e) e+32 32 s s s - )) 
	  :pitch-seq-palette (4 5 4 4 5 4 5 4 7 13 17 15 14 15 11 12 13 4 5 7 8) 
	  :cmn-marks (ff 1 slur 1 2 s 3 slur 4 5 a 6 slur 8 10 s 10 a 11 s 11 a 12
			 s 12 slur 13 15 slur 16 17 a 18 slur 19 22)))) 

 ;; Now we assign the individual rhythm sequences (and accompanying melodic
 ;; contours) we've created to instruments from our ensemble for each section
 ;; of our composition by making a rhythm sequence map. There must be 
 ;; equally as many sections for this map as for the (pitch) set map. There
 ;; must also be equally as many rhythm sequences in each list for each
 ;; instrument of each section as there are pitch sets in the set-map for that
 ;; section. The first item in each list is the variable defined in the
 ;; :ensemble section for the given instrument you are managing. The numbers
 ;; within each list refer to the rhythm sequences defined in the rhythm
 ;; sequence palette.
 :rthm-seq-map
 '((1
    ((flt (seq1 seq1 seq1 seq1 seq1))  
     (tpt-c (seq1 seq2 seq1 seq2 seq1))  
     (vln-one (seq1 seq2 seq1 seq2 seq1))  
     (vln-two (seq1 seq2 seq1 seq2 seq1))  
     (vla (seq1 seq2 seq1 seq2 seq1))  
     (cel (seq1 seq2 seq1 seq2 seq1))  
     (db (seq1 seq2 seq1 seq2 seq1))))  
   (2
    ((flt (seq1 seq2 seq1 seq2 seq1 seq2 seq1))  
     (tpt-c (seq1 seq2 seq3 seq1 seq2 seq3 seq1))   
     (vln-one (seq1 seq2 seq1 seq2 seq1 seq2 seq1))  
     (vln-two (seq1 seq2 seq3 seq1 seq2 seq3 seq1))  
     (vla (seq1 seq2 seq1 seq2 seq1 seq2 seq1))  
     (cel (seq1 seq2 seq3 seq1 seq2 seq3 seq1))  
     (db (seq1 seq2 seq3 seq1 seq2 seq3 seq1))))  
   (3 
    ((flt (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1))  
     (tpt-c (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq3 seq2 seq1))  
     (vln-one (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1))  
     (vln-two (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq3 seq2 seq1))  
     (vla (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1))  
     (cel (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq3 seq2 seq1))  
     (db (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq3 seq2 seq1))))  
   (4 
    ((flt (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1
		seq1 seq1))  
     (tpt-c (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1
		  seq1 seq1)) 
     (vln-one (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1
		    seq1 seq1)) 
     (vln-two (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1
		    seq1 seq1)) 
     (vla (seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1 seq2 seq3 seq4 seq1
		seq1 seq1)) 
     (cel (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1
		seq1 seq1)) 
     (db (seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1 seq1
	       seq1)))))) 

;; Finally, we are ready to produce some output.

;; MIDI output can be generated by slippery chicken without the help of any
;; additional software applications or packages. It is produced using using the
;; midi-play function together with the variable defined in the very beginning
;; for the music generated, as shown below. 

;; The midi-play function has two mandatory arguments in addition to the
;; variable for the music. The first of these is the point in the piece from
;; which we want to start the output. We indicate this value with the section
;; ID as defined above. In our example we start from section 1.  

;; The other additional required argument is the path file name of the MIDI
;; file to be created. For the sake of this introduction we will use the /tmp/
;; directory for the path, as most systems have this. You can, of course,
;; change this to your own directory of choice. The file name you choose should
;; end with the .mid suffix for ease of opening after generation.

;; The midi-play function can take several more specific parameters as well,
;; which will be discussed in more detail elsewhere. 

(midi-play +primary-disposition+ 1 
           :midi-file
           "/tmp/primary-disposition.mid")

;; The first typeset output we will look at is that using LilyPond. This
;; function of slippery chicken generates a series of LilyPond scripts for your
;; composition using the value you assigned to the :title keyword as the base
;; name for the files generated. It will create a file for the full score,
;; which can be easily found by the underscore set at the beginning of the file
;; name and the -score.ly appended to the end of the file name. To generate the
;; printable version of the full score from this LilyPond file, open it in your
;; LilyPond application and render the output. 

;; Files are also generated for each of the individual instruments
;; ("parts"). They can be identified by the suffix -part.ly that is appended to
;; the file name, and the variable you assigned to each instrument above. The
;; -def.ly files generated contain the actual musical content for the
;; parts. You do not need to access these directly, but LilyPond needs them in
;; order to be able to generate the parts.

;; The write-lp-data-for-all function is used to generate the LilyPond
;; files. As with all of the output functions, this function takes as its first
;; required argument the variable named at the beginning of your
;; slippery chicken script. 

;; The only other argument that must be defined for the simplest form of
;; LilyPond output is the output path. As opposed to the requirements for the
;; MIDI output, the write-lp-data-for-all function only wants the path, and not
;; the file name, as slippery chicken automatically generates the file names
;; for LilyPond as described above.  

;; As with the midi-player function, this function has many other optional
;; arguments which will be discussed in more detail elsewhere. 
 
;; NB: LilyPond can take a long time to generate your score, during which time
;; it is unresponsive and may appear to have hung or frozen.

;; To generate LilyPond files, uncomment the following two lines (delete the
;; semi-colons). 

;; (write-lp-data-for-all +primary-disposition+
;;   		       "/tmp/")

;; The final output option is typeset by Common Music Notation using the
;; cmn-display function. This function, too, takes as its first required
;; argument the variable defined at the beginning of your slippery chicken
;; script. A second important argument is the :write-section-info argument,
;; which prints information about the slippery chicken script into the score
;; and should be set to nil if only music is desired. The last required
;; argument is the path and file name. As with the midi-play function, you have
;; to include the file name in addition to the path. CMN generates encapsulated 
;; post-script files, so be sure to add the .eps suffix to your file name to
;; facilitate opening the file later. 

;; The keyword argument :bars-per-system-map set at the beginning of your
;; slippery chicken file will determine how many measures are placed in each
;; system of the typeset CMN output. 

;; To generate an .eps file using the interaction between slippery chicken and
;; CMN, uncomment the following three lines (delete the semi-colons).
 
;; (cmn-display +primary-disposition+
;; 	     :write-section-info nil 
;; 	     :file "/tmp/primary-disposition.eps")

;; As long as CMN is installed and set up properly to interact with slippery
;; chicken, you can generate both LilyPond and CMN output, as well as a MIDI
;; file, at the same time. 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; EOF primary-disposition.lsp
